package org.neframework.webtest.service;

import java.sql.Timestamp;
import java.util.Map;

import org.neframework.webtest.model.t_s_system;
import org.neframework.webtest.util.date.DateTools;
import org.neframework.webtest.util.verify.VerifyTools;

import com.tmsps.neframework.jpa.base.BaseService;

public class VerifyService extends BaseService {

	public static void main(String[] args) {
	}

	public t_s_system selectVerifyInfo() {
		String sql = "select * from t_s_system t where t.status=0 and t.name='verify' ";
		t_s_system verify = (t_s_system) oc.findObj(sql, t_s_system.class);
		if (verify == null) {
			verify = new t_s_system();
			verify.setName("verify");
			verify.setEnddate(DateTools.addDay(
					new Timestamp(System.currentTimeMillis()), 10));
			verify.setStatus_verify("已验证");
			oc.saveObj(verify);
		}
		return verify;
	}

	public boolean updateVerifyInfo(String code, Long enddate) {
		Map<String, Object> end = VerifyTools.setVerifyInfo(code);
		if ("true".equals(end.get("end"))) {
			t_s_system verifyInfo = selectVerifyInfo();
			verifyInfo.setCode(code);
			verifyInfo.setEnddate(new Timestamp(enddate));
			oc.updateObj(verifyInfo);
			return true;
		}
		return false;
	}

}
